class Building:
    def __init__(self, name: str):
        self.name = name

    def __repr__(self):
        return f"Building({self.name})"


class Course:
    def __init__(self, course_name: str, building: Building):
        self.course_name = course_name
        self.building = building  # 约束：每个课程都必须在某个建筑中

    def __repr__(self):
        return f"Course({self.course_name}, located in {self.building.name})"


class College:
    def __init__(self, name: str):
        self.name = name
        self.buildings = []  # 学院包含的建筑（聚合）
        self.courses = []    # 学院包含的课程（组合）

    def add_building(self, building: Building):
        self.buildings.append(building)

    def add_course(self, course: Course):
        if course.building in self.buildings:  # 确保课程所在的建筑在学院的建筑列表中
            self.courses.append(course)
        else:
            raise ValueError("Course building must be part of the college buildings.")

    def __repr__(self):
        return f"College({self.name}, Buildings: {self.buildings}, Courses: {self.courses})"

